package com.zhoug.permission3demo;

import android.Manifest;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import com.zhoug.permission3.ZPermissions;

import java.util.ArrayList;


public class MainActivity extends MyBaseActivity {

    private Button mBtn1;
    private Button mBtn2;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void findViews() {

        mBtn1 = findViewById(R.id.btn_1);
        mBtn2 = findViewById(R.id.btn_2);
    }

    @Override
    protected void onCreate1(Bundle savedInstanceState) {
        mBtn1.setOnClickListener(v->{
            ZPermissions.with(this)
                    .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE)
                    .setDescription("需要存储权限")
                    .setShowDescription(true)
                    .setShowNoAsking(true)
                    .setCallback(new ZPermissions.Callback() {
                        @Override
                        public void onRequestPermissionsResult(boolean success, ArrayList<String> granted, ArrayList<String> denied) {
                            if(success){
                                Toast.makeText(MainActivity.this, "权限申请成功", Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(MainActivity.this, "权限申请失败", Toast.LENGTH_SHORT).show();
                            }
                        }
                    })
                    .request();
        });

        mBtn2.setOnClickListener(v->{
            ZPermissions.with(this)
                    .setPermissions(Manifest.permission.CAMERA)
                    .setDescription("需要相机权限")
                    .setShowDescription(true)
                    .setShowNoAsking(true)
                    .setCallback(new ZPermissions.Callback() {
                        @Override
                        public void onRequestPermissionsResult(boolean success, ArrayList<String> granted, ArrayList<String> denied) {
                            if(success){
                                Toast.makeText(MainActivity.this, "权限申请成功", Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(MainActivity.this, "权限申请失败", Toast.LENGTH_SHORT).show();
                            }
                        }
                    })
                    .request();
        });
    }

}